﻿package com.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import com.entity.User;
import com.util.DBHelp;
import com.util.RowMapper;
//这是一个USERDAO

public class  UserDao {
	private DBHelp<User> db=new DBHelp<User>();
	public User findByName(String name){
		String sql="select id,username,`password`,kind,image from t_user where name=?";
		return db.executeQueryForObject(sql, new UserRowMapper(),name);
	}
	
	private class UserRowMapper implements RowMapper<User>{

		public User mapRow(ResultSet rs) throws SQLException {
			User user=new User();
			user.setId(rs.getInt("id"));
			user.setImage(rs.getString("image"));
			user.setKind(rs.getString("king"));
			user.setPassword(rs.getString("password"));
			user.setUserName(rs.getString("username")); 
			return user;
		}
		
		
		
	}
}
